package com.pmcc.core.web;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.pmcc.core.dto.Menu;
import com.pmcc.core.entity.enums.ModuleType;
import com.pmcc.core.entity.security.Authority;
import com.pmcc.core.repository.AuthorityRepository;
import com.pmcc.core.service.AuthorityService;
import com.pmcc.utils.AntdPage;
import com.pmcc.utils.ResultBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by syk on 17/7/6.
 */
@RestController()
@RequestMapping("api/v1/menus")
public class MenuController {

   /* @Autowired
    AuthorityService authorityService;

    @Autowired
    AuthorityRepository authorityRepository;

    @Autowired
    EmployeeController employeeController;
*/

    /*@RequestMapping(value = "queryList",method = RequestMethod.GET)
    @ResponseBody
    public ResultBean queryList(Menu menu){
        return authorityService.queryList(null,menu);
    }

    @GetMapping("")
    public ResultBean list(AntdPage antdPage, Menu menu) {
       *//* Map<String,List> map=new HashMap<>();
        map.put("list",authorityService.getAllMenus());
       return map;*//*
        return authorityService.queryList(antdPage,menu);
    }

    *//**
     * 删除
     * @param ids
     * @return
     *//*
    @DeleteMapping()
    public ResultBean delete(String ids){
        ResultBean resultBean=new ResultBean(ResultBean.SUCCESS);
        if(ids!=null){
            String [] idArr=ids.split(",");
            for (String id:idArr) {
                authorityRepository.delete(id);
            }
        }
        return resultBean;
    }


    @GetMapping("treeNodes")
    public String getMenuTreeNodes(){



        return "success";
    }


    @PostMapping("")
    public String create(@RequestBody Menu menu){
        Authority authority = new Authority();
        authority.setName(menu.getName());
        authority.setCreateTime(new Date());
        authority.setIcon(menu.getIcon());
        authority.setModuleType(ModuleType.MENU);
        authority.setRouter(menu.getRoute());
        authority.setParentId(menu.getBpid()==null?menu.getBpid():menu.getMpid());
        authority.setId(menu.getId());
        authorityRepository.save(authority);
        return "success";
    }


    @GetMapping(value = "queryMenuByToken")
    public Map<String,List> queryMenuByToken(HttpServletRequest request){
        Map<String,List> map=new HashMap<>();
        String token=request.getHeader("token");
        map.put("list",authorityService.queryMenuByToken(token));
        return map;
    }*/
}
